//
// Created by lfm on 25-4-8.
//

#include "MyArray.h"

MyArray::MyArray(int leng)
{
    if (leng <= 0)
    {
        cout << "error length" << endl;
        exit(1);
    }
    alist = new int[leng];
    length = leng;
    if (alist == NULL)
    {
        cout << "assign failure" << endl;
        exit(1);//?
    }
    cout << "MyArray类对象已创建." << endl;
}

MyArray::~MyArray()
{
    delete[] alist;
    cout << "MyArray类对象被撤销." << endl;
}

void MyArray::Input()
{
    cout << "请从键盘输入" << length << "个整数: ";
    for (int i = 0; i < length; i++)
    {
        cin >> alist[i];
    }
}

void MyArray::Display(string str)
{
    cout << str << length << "个整数: ";
    for (int i = 0; i < length; i++)
    {
        cout << alist[i] << " ";
    }
    cout << endl;
}